<?php

class Mail_template_model extends MY_Model
{

	public function __construct()
	{
		parent::__construct();
	}
	
	public function head()
	{
		return $this->db
			->select("SQL_CALC_FOUND_ROWS mt.*", FALSE)
			->from('mail_template AS mt');
	}

	public function add($data = array())
	{
		$this->db->insert('mail_template', $data);
	}

	public function gets($options = array(), $limit = 0, $offset = 0)
	{
		$this
			->head()
			->order_by('mt.id', 'desc');
			
		// WHERE
		if(isset($options['user_id']))
			$this->db->where('mt.user_id', $options['user_id']);			
			
		return parent::my_result($limit, $offset);
	}

	public function get($id)
	{
		$q = $this
			->head()
			->where('mt.id', $id)
			->get();
			
		if($q->num_rows()) return $q->row();
		
		return FALSE;
	}

	public function edit($data = array(), $options = array())
	{
		$this->db->update('mail_template', $data, $options);
	}

	public function delete($options = array())
	{
		$this->db->delete('mail_template', $options);
	}
}

/* End of file mail_template_model.php */
